<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>标签管理</title>
    <script type="text/javascript">

    </script>
</head>
<body>
<script type="text/javascript">
    $(function() {
        $("#userInfoEditStatus").val("${user.status}");
        $("#userInfoEditType").val("${user.type}");
        console.log("editFun1");
        $('#userInfoEditForm').form({
            url : '${path }/userInfo/edit.do',

            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success : function(result) {
                console.log("editFun1  result"+result);
                progressClose();
                result = $.parseJSON(result);
                console.log("editFun2  result"+result);
                if (result.success) {
                    parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
                    parent.$.modalDialog.handler.dialog('close');
                } else {
                    var form = $('#userInfoEditForm');
                    parent.$.messager.alert('错误', eval(result.msg), 'error');
                }
            }
        });
        
    });

</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false" title="" style="overflow: hidden;padding: 3px;">
        <form id="userInfoEditForm" method="post">
            <table class="grid">
                <input type="hidden" id="edit_id" name="id" value="${user.id}"/>
                <input type="hidden" id="edit_provinceId" name="provinceId" value="${user.provinceId}"/>
                <input type="hidden" id="edit_province" name="province" value="${user.province}"/>
                <input type="hidden" id="edit_cityId" name="cityId" value="${user.cityId}"/>
                <input type="hidden" id="edit_city" name="city" value="${user.city}"/>
                <input type="hidden" id="edit_areaId" name="areaId" value="${user.areaId}"/>
                <input type="hidden" id="edit_area" name="area" value="${user.area}"/>
                <tr>
                    <td>头像</td>
                    <td>
                        <div id="upload_ue"></div>
                        <div><img id="headurl" src="${user.headurl}" height="80" width="80"></div>
                    </td>

                    <td> <input type="hidden" id="picture" name="headurl" value="${user.headurl}"/>
                        <input type="button" onclick="upImage();" value="上传图片">
                    </td>

                </tr>
                <tr>
                    <td>类型</td>
                    <td>
                        <select id="userInfoEditType" name="type"  class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto'">
                            <option value="1">商家</option>
                            <option value="0">用户</option>
                            <option value="2">员工</option>
                            <option value="3">专家</option>
                            <option value="4">企业</option>
                        </select>
                    </td>
                    <td>状态</td>
                    <td>
                        <select id="userInfoEditStatus" name="status" class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto'">
                            <option value="1">启用</option>
                            <option value="0">停用</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>用户名</td>
                    <input type="hidden" name="id" value="${user.id}">
                    <td><input name="username"  value="${user.username}" type="text" placeholder="请输入用户名" class="easyui-validatebox span2" data-options="required:true" ></td>
                    <td>手机号</td>
                    <td><input name="phone" value="${user.phone}" type="text" placeholder="请输入手机号" class="easyui-validatebox span2" data-options="required:true" ></td>

                </tr>



                <tr>
                    <td>昵称</td>
                    <td><input name="nickname" value="${user.nickname}" type="text" placeholder="请输入昵称" class="easyui-validatebox span2"  ></td>
                    <td>生日</td>
                    <td><input name="birthdayTemp" value="${user.birthday}" type="text" placeholder="请输入生日" class="easyui-datebox"></td>
                    <td>邮箱</td>
                    <td><input name="email" value="${user.email}" type="text" placeholder="请输入邮箱" class="easyui-validatebox span2"  ></td>


                </tr>

                <tr>
                    <td>长居地省</td>
                    <td >
                        <input id="delivery_address_province" class="easyui-combobox"
                               data-options="missingMessage:'请选择省份',
                                         url:'${path}/areaInfo/addressList.do?type=1',
                                         valueField:'id',
                                         textField:'name',
                                         editable:false,
                                         onLoadSuccess:function(data){
                                            <%--if('${user.provinceId != 0}' || '${user.provinceId != null}'){--%>
                                                $(this).combobox('setValue','${user.provinceId}');
                                            <%--}else{--%>
                                                <%--$(this).combobox('setValue',data[0].id);--%>
                                            <%--}--%>
                                         },
                                         onChange: function (newValue, oldValue){
                                             $('#delivery_address_city').combobox('clear');
                                             $('#delivery_address_city').combobox('reload','${path}/areaInfo/addressList.do?type=2&pid='+newValue);
                                         },
                                         onSelect:function(data){
                                             $('#edit_provinceId').val(data.id);
                                             $('#edit_province').val(data.name);
                                         }" />
                    </td>
                    <td>长居地市</td>
                    <td >
                        <input id="delivery_address_city" class="easyui-combobox "
                               data-options="missingMessage:'请选择城市',
                                         valueField:'id',
                                         textField:'name',
                                         editable:false,
                                         onLoadSuccess:function(data){
                                            <%--if('${user.cityId != 0}' || '${user.cityId != null}){--%>
                                                $(this).combobox('setValue','${user.cityId}');
                                            <%--}else{--%>
                                                <%--$(this).combobox('setValue',data[0].id);--%>
                                            <%--}--%>
                                         },
                                         onChange: function (newValue, oldValue){
                                             $('#delivery_address_area').combobox('clear');
                                             $('#delivery_address_area').combobox('reload','${path}/areaInfo/addressList.do?type=3&pid='+newValue);
                                         },
                                         onSelect:function(data){
                                             $('#edit_cityId').val(data.id);
                                             $('#edit_city').val(data.name);
                                         }"/>
                    </td>
                    <td>长居地区</td>
                    <td >
                        <input id="delivery_address_area" class="easyui-combobox "
                               data-options="missingMessage:'请选择区县' ,
                                         valueField:'id' ,
                                         textField:'name',
                                         editable:false,
                                         onLoadSuccess:function(data){
                                            <%--if('${user.areaId != 0} || '${user.areaId  != null}'){--%>
                                                $(this).combobox('setValue','${user.areaId}');
                                            <%--}else{--%>
                                                <%--$(this).combobox('setValue',data[0].id);--%>
                                            <%--}--%>
                                         },
                                         onSelect:function(data){
                                            $('#edit_areaId').val(data.id);
                                            $('#edit_area').val(data.name);
                                         }" />
                    </td>
                </tr>
                <tr>
                    <td>姓名</td>
                    <td><input name="trueName" value="${user.trueName}" type="text" placeholder="请输入姓名" class="easyui-validatebox span2"  ></td>

                    <td>性别</td>
                    <td>
                        <select name="sex"  class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto'">
                            <option value="0">男</option>
                            <option value="1">女</option>
                        </select>
                    </td>
                    <td>年龄</td>
                    <td><input name="age" value="${user.age}" type="text" placeholder="请输入年龄" class="easyui-validatebox span2"  ></td>

                   </tr>

                <tr>
                    <td>余额</td>
                    <td>￥${user.money}</td>

                    <td>注册时间</td>
                    <td><fmt:formatDate value="${user.regTime}" pattern="yyyy-MM-dd"/> </td>

                </tr>
            </table>
        </form>
    </div>
</div>
<script type="text/javascript">

    var _editor;
    $(function() {
        //重新实例化一个编辑器，防止在上面的editor编辑器中显示上传的图片或者文件
        _editor = UE.getEditor('upload_ue',{
            serverUrl:"${path}/file/upload.do?compress=1"
        });

        _editor.ready(function () {
            //设置编辑器不可用
            // _editor.setDisabled();
            //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
            _editor.hide();
            //侦听图片上传
            _editor.addListener('beforeInsertImage', function (t, arg) {
                //有多少张图片arg.length就是多大
                $("#picture").val(arg[0].src);
                $("#headurl").attr('src',arg[0].src);
            });
        });
    });
    //弹出图片上传的对话框
    function upImage() {
        var myImage = _editor.getDialog("insertimage");
        myImage.open();
    }
</script>

</body>
</html>